package com.linlong.linlongchat.controller.user;


import com.linlong.linlongchat.domain.dto.UserDto;
import com.linlong.linlongchat.domain.po.Result;
import com.linlong.linlongchat.service.IUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author 华少
 * @since 2024-09-19
 */
@RestController
@RequestMapping("/user")

public class UserController {
        @Autowired
        private IUserService userService;

        /**
         * 发送验证码
         *  /user/sendEmail?email=xxx  GET请求
         * @param email
         * @return
         */
        @GetMapping("/sendEmail")
        public Result<String> sendEmail(String email) {
                return userService.sendEmail(email);
        }
        /**
         * 账号密码登录
         * /user/login  username=xxx&password=xxx  POST请求
         * @param username 用户名
         * @param password 密码
         * @return 登录结果
         */
        @PostMapping("/login")
        @ApiOperation("账号密码登录")
        public Result<String> login(String username, String password) {
                return userService.login(username, password);
        }

        /**
         * 用户注册方法
         * /user/register  nickName=xxx&email=xxx&code=xxx&password=xxx  POST请求
         * @return
         */
        @PostMapping("/register")
        public Result register(String nickName, String email, String code, String password) {
                return userService.register(nickName, email, code, password);
        }
}
